3  Tests

(ns scicloj.scrapbook.tests
  (:require [tablecloth.api :as tc]
            [scicloj.kindly.v3.kind :as kind]
            [scicloj.clay.v2.api :as clay
             :refer [is->]]))

3.0.1 clojure.test

Standard Clojure tests may be integrated into notebooks.

(require '[clojure.test :refer [deftest is]])
nil

Tests returning a boolean value (as they usually do, ending with a check) are rendered displaying that value as a clear x (failure) or v (success) mark:

(def test-dataset
  (tc/dataset {:x [1 2 3]
               :y [4 5 6]}))
(deftest mytest1
  (-> test-dataset
      tc/row-count
      (= 3)
      is))

Tests returning a non-boolean value are rendered simply displaying that value:

(deftest mytest2
  (-> test-dataset
      tc/row-count
      (= 3)
      is)
  test-dataset)

The is-> function allows performing a few checks in a pipeline and returning a different value to be displayed:

(deftest mytest3
  (-> 2
      (+ 3)
      (is-> > 4)
      (* 10)
      (is-> = 50)
      (* 10)))
500
These features open the way for literate testing / testable documentation solutions, such as those we have been using in the past (e.g., in tutorials of ClojisR using Notespace v2).